package leetcode;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

public class Offer06V2 {

    List<Integer> list = new ArrayList<Integer>();

    public int[] reversePrint(ListNode head) {
        reverse(head);
        int[] result = new int[list.size()];
        for (int i=0;i<list.size();i++){
            result[i]=list.get(i);
        }
        return result;
    }

    public void reverse(ListNode node) {
        if (node == null) {
            return;
        }
        reverse(node.next);
        list.add(node.val);
    }

    public class ListNode {
        int val;
        ListNode next;
        ListNode(int x) { val = x; }
    }
}
